package com.team.mapper;

import com.team.entity.SysUsers;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.team.util.MenuDto;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
* @author asus
* @description 针对表【sys_users(用户表)】的数据库操作Mapper
* @createDate 2024-07-13 14:39:20
* @Entity com.team.entity.SysUsers
*/
public interface SysUsersMapper extends BaseMapper<SysUsers> {
    @Select("SELECT id,user_Type AS userType,account,user_name AS username,created_time AS createdTime, ,created_user_id as createdUserId CASE user_type WHEN 1 THEN '系统管理员' WHEN 2 THEN '挂号员' WHEN 3 THEN '门诊医师' WHEN 4 THEN '收银员' WHEN 5 THEN '药房医师' END AS typename  FROM sys_users")
    public List<SysUsers> getAllUsers();
    @Select("select * from sys_users where id = #{id}")
    SysUsers getSysUsers(Integer id);
    @Update("update sys_users set password = #{password},head_url=#{headUrl} where id = #{id}")
    int updateUser(@Param("id")Integer id,@Param("password")String password,@Param("headUrl")String headUrl);
    //通过用户编号id找一级菜单
    @Select("SELECT m.id AS id,menu_name AS menuName,menu_url AS menuUrl,menu_type AS menuType,parent_id AS parentId,m.created_time AS createdTime,m.updated_time AS updateTime FROM sys_menus m LEFT JOIN sys_roles_menus rm ON rm.menu_id=m.id LEFT JOIN sys_users_roles ur ON rm.role_id=ur.role_id LEFT JOIN sys_users u ON u.id=ur.user_id WHERE  m.`parent_id` IS NULL AND u.id=#{uid}")
    List<MenuDto> getMenuByUser(Long uid);
    //通过一级菜单的编号查找对应的二级菜单
    @Select("SELECT m.id AS id,menu_name AS menuName,menu_url AS menuUrl,menu_type AS menuType,parent_id AS parentId,m.created_time AS createdTime,m.updated_time AS updateTime FROM sys_menus m WHERE  parent_Id=#{pid}")
    List<MenuDto> getMenuByPid(Integer pid);
}




